/*
 * SubmitOrderSuccessProvider.java
 * business
 *
 * Created by chentao on 2017/5/9.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.recyclerview.provider;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.response.QueryMultiPayWaysResultResponse;
import com.yidiandao.business.utils.UIUtils;

import me.drakeet.multitype.ItemViewProvider;

/**
 * 多订单订单信息
 * <p>
 * Created by ChenTao(chentao7v@gmail.com) on 2017/5/9 0009 9:57
 */
public class MultiPayWayInfoProvider extends ItemViewProvider<QueryMultiPayWaysResultResponse.PayWayState, MultiPayWayInfoProvider.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_multi_pay_ways, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull QueryMultiPayWaysResultResponse.PayWayState state) {
        String orderStatus = state.getOrderStatus();
        String payName = state.getPayName();
        String money = state.getMoney();
        // 0 未支付，1已支付
        int status = state.getStatus();

        holder.tvOrderStatistics.setText(payName + "：￥" + money);
        holder.tvOrderState.setText(orderStatus);

        int resId = (status == 0) ? R.mipmap.ic_order_failed : R.mipmap.ic_order_success;
        int color = (status == 0) ? R.color.text_color_8 : R.color.btn_red;
        holder.ivOrderState.setBackgroundResource(resId);
        holder.tvOrderState.setTextColor(UIUtils.getColor(color));
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvOrderStatistics;
        private TextView tvOrderState;
        private ImageView ivOrderState;

        public ViewHolder(View itemView) {
            super(itemView);
            tvOrderStatistics = (TextView) itemView.findViewById(R.id.tv_order_statistics);
            tvOrderState = (TextView) itemView.findViewById(R.id.tv_order_state);
            ivOrderState = (ImageView) itemView.findViewById(R.id.iv_order_state);
        }
    }
}
